package com.cjy.controller.user;

import com.cjy.common.message.AjaxResult;
import com.cjy.common.message.RequestPageHead;
import com.cjy.common.message.ResultPage;
import com.cjy.service.user.IUserService;
import com.cjy.entity.user.UserEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import com.cjy.common.message.BaseResult;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * @Description 用户表控制器
 * @Author chengjiye
 * @Date 2020-11-12 13:46
 */
@SuppressWarnings("ALL")
@Api(tags = "用户表接口")
@RestController
@RequestMapping("/user/")
@Slf4j
public class UserController {

    @Autowired
    private IUserService userService;

    @ApiOperation(value = "获取用户表列表")
    @PostMapping("list")
    public ResultPage<List<UserEntity>> list(@RequestBody RequestPageHead req) {
        log.debug("UserController::list ...");
        return BaseResult.packPageResult(userService.queryUserEntityList(req));

    }

    @ApiOperation(value = "按userId获取用户表详情")
    @PostMapping("detail")
    public AjaxResult detail(@RequestBody UserEntity reqDetail) {
        log.debug("UserController::detail ...");
        return AjaxResult.success(userService.queryUserEntityById(reqDetail));
    }

    @ApiOperation(value = "新增用户表")
    @PostMapping("add")
    public AjaxResult add(@RequestBody UserEntity reqAdd) {
        log.debug("UserController::add ...");
        userService.insertUserEntity(reqAdd);
        return AjaxResult.success();
    }

    @ApiOperation(value = "按id删除用户表")
    @PostMapping("delete")
    public AjaxResult delete(@RequestBody UserEntity reqDelete) {
        log.debug("UserController::delete ...");
        userService.deleteUserEntityById(reqDelete);
        return AjaxResult.success();
    }

    @ApiOperation(value = "按id修改用户表")
    @PostMapping("edit")
    public AjaxResult edit(@RequestBody UserEntity reqEdit) {
        log.debug("UserController::edit ...");
        userService.updateUserEntityById(reqEdit);
        return AjaxResult.success();
    }

}
